'use strict';
import * as types from '../../constants/ActionTypes';
import {Tool} from '../../Tool'
const initialState = {
    users: [],
    user: {},
    token: [],
    list: [],
    babyname: '',
    babyid: '',
    jxtBabyId: '',
    deviceType: '',
    acindex: 0,
    babytelephone: '',
    deviceid:'',
    headimg: '',
    values: '',
    lng: '',
    lat: '',
    getGuardiansList: [],
    getGuardiansLists: [],
    gpstime: '',
    checked: false,
    relationList: false,
    addr: '',
    isLong: [],
    datasource: [],
    GetSafeRegions: [],
    exportMap: []
};
export default function login(state = initialState, action) {
    switch (action.type) {
        case types.SET_USER:
            return {users: action.data.users};
        case types.GET_TOKEN:
            return {token: action.res.token};
        case types.GetDeviceList:
            const acindex=action.res[0].acindex;
            return Tool.assign({}, state, {
                list: action.res,
                babyname: action.res[acindex].babyname,
                babyid: action.res[acindex].babyid,
                jxtBabyId: action.res[acindex].jxtBabyId,
                deviceType: action.res[acindex].deviceType,
                authstatus: action.res[acindex].authstatus,
                loststatus: action.res[acindex].loststatus,
                babytelephone: action.res[acindex].babytelephone,
                deviceid: action.res[acindex].deviceid,
                headimg: action.res[acindex].headimg,
                getGuardiansList: [],
                addr: '',
                acindex
            });
        case types.GetChecked:
            return Tool.assign({}, state, {
                checked: action.msg,
                getGuardiansList: [],
                addr: ''
            });
        case types.Change:
            return Tool.assign({}, state, {
                babyname: action.res.babyname,
                babyid: action.res.babyid,
                jxtBabyId: action.res.jxtBabyId,
                deviceType: action.res.deviceType,
                acindex: action.res.acindex,
                authstatus: action.res.authstatus,
                loststatus: action.res.loststatus,
                babytelephone: action.res.babytelephone,
                deviceid: action.res.deviceid,
                headimg: action.res.headimg,
                getGuardiansList: [],
                addr: ''
            });
        case types.GetGuardians:
            return Tool.assign({}, state, {getGuardiansList: action.res});
        case types.GetGuardianss:
            return Tool.assign({}, state, {getGuardiansLists: action.res});
        case types.GetCurrentTrack:
            return Tool.assign({}, state, {
                lng: action.res.lng,
                lat: action.res.lat,
                gpstime: action.res.gpstime,
                addr: '',
                datasource: action.res.datasource

            });
        case types.GetAddr:
            return Tool.assign({}, state, {addr: action.msg});
        case types.aaa:
            return Tool.assign({}, state, {relationList: action.msg});
        case types.isLogin:
            return Tool.assign({}, state, {isLogin: action.msg});
        case types.GetCurrentPower:
            return Tool.assign({}, state, {
                values: action.res,
                getGuardiansList: [],
                addr: ''
            });
        case types.GetSafeRegions1:
            return Tool.assign({}, state, {GetSafeRegions: action.res});
        case types.exportMap:
            return Tool.assign({}, state, {exportMap: action.res});
        default:
            return state;
    }
}
